<!DOCTYPE html>
<html lang="zh">
<#
 include "head.html";
 #>
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <#
     include "lefter.html";
     #>
    <!--End 左侧导航-->
    <!--头部信息-->
    <#
     include "header.html";
     #>
    <!--End 头部信息-->
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                
                <form method="post" action="#!" class="site-form">
                  <div class="form-group">
                    <label for="name">名称</label>
                    <input type="text" class="form-control" name="name" id="name" placeholder="输入名称" value="${server.name}">
                  </div>
                  <div class="form-group">
                    <label for="ip">IP</label>
                    <input type="text" class="form-control" name="ip" id="ip" placeholder="输入IP(例如：127.0.0.1)" value="${server.ip}">
                  </div>
                  <div class="form-group">
                    <label for="port">端口</label>
                    <input type="text" class="form-control" name="port" id="port" placeholder="输入端口(例如：9799)" value="${server.port}">
                  </div>
                  <div class="form-group">
                    <label for="protocol">协议</label>
                    <select class="form-control" id="protocolType" name="protocolType" size="1">
                      <option value="0" ${ga:selected($server.protocolType, 0)}>所有</option>
                      <option value="1" ${ga:selected($server.protocolType, 1)}>HTTP</option>
                      <option value="2" ${ga:selected($server.protocolType, 2)}>TCP</option>
                    </select>
                  </div>
                  <div class="form-group">
                    <label for="domain">域名</label>
                    <input type="text" class="form-control" name="domain" id="domain" placeholder="输入端口(例如：jiucheng.org)" value="${server.domain}">
                  </div>
                  <div class="form-group">
                    <label for="blackPorts">黑名单端口</label>
                    <input type="text" class="form-control" name="blackPorts" id="blackPorts" placeholder="输入黑名单端口(例如：0-1024,8080)" value="${server.blackPorts}">
                  </div>
                  <div class="form-group">
                    <label for="blackSubs">黑名单子域名</label>
                    <input type="text" class="form-control" name="blackSubs" id="blackSubs" placeholder="黑名单子域名(例如：www,wap,3g,blog)" value="${server.blackSubs}">
                  </div>
                  <div class="form-group">
                    <label for="token">令牌（<a href="javascript:tokenChange()" title="更换" data-toggle="tooltip">更换</a>）</label>
                    <#
                     if ($isSuper == "T")
                     #>
                    <input type="text" class="form-control" name="token" id="token" placeholder="令牌" value="${server.token}" disabled>
                    <#
                     else
                     #>
                    <input type="text" class="form-control" name="token" id="token" placeholder="令牌" value="********************************" disabled>
                    <#
                     fi;
                     #>
                  </div>
                  <button type="button" class="btn btn-primary" id="letsgo">保存</button>
                </form>
       
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<#
 include "js.html";
 #>
<script src="js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="js/lightyear.js"></script>
<script type="text/javascript">
function tokenChange() {
    lightyear.loading('show');
    $.ajax({
        type: "POST",
        url: "/openapi/v1/server/token/change",
        contentType: "application/json;charset=utf-8",
        data:JSON.stringify({id:${server.id}}),
        dataType: "json",
        success:function (message) {
            lightyear.loading('hide');
            if (message.sta == 0) {
                $('#token').val(message.obj);
                lightyear.notify('更换成功', 'success', 1000);
            } else {
                lightyear.notify(message.msg, 'danger', 1000);
            }
        },
        error:function (message) {
            lightyear.loading('hide');
            lightyear.notify('服务器错误，请稍后再试~', 'danger', 100);
        }
    });
}
$('#letsgo').on('click', function(){
    if ($('#name').val() == '') {
        lightyear.notify('名称不能为空', 'danger', 1000);
        return;
    }
    if ($('#ip').val() == '') {
        lightyear.notify('IP不能为空', 'danger', 1000);
        return;
    }
    if ($('#port').val() == '') {
        lightyear.notify('端口不能为空', 'danger', 1000);
        return;
    }
    if ($('#domain').val() == '') {
        lightyear.notify('域名不能为空', 'danger', 1000);
        return;
    }
    lightyear.loading('show');
    $.ajax({
        type: "POST",
        url: "/openapi/v1/server/edit",
        contentType: "application/json;charset=utf-8",
        data:JSON.stringify({id:${server.id},"name":$('#name').val(),"ip":$('#ip').val(),"port":$('#port').val(),"protocolType":$('#protocolType').val()
        						,"domain":$('#domain').val(),"blackPorts":$('#blackPorts').val(),"blackSubs":$('#blackSubs').val()}),
        dataType: "json",
        success:function (message) {
            lightyear.loading('hide');
            if (message.sta == 0) {
                lightyear.notify('保存成功', 'success', 1000);
            } else {
                lightyear.notify(message.msg, 'danger', 1000);
            }
        },
        error:function (message) {
            lightyear.loading('hide');
            lightyear.notify('服务器错误，请稍后再试~', 'danger', 100);
        }
    });
});
</script>
</body>
</html>